import java.util.Arrays;

public class MyStack implements IStack{

    // 用数组来实现栈
    public int[] iml;
    private int usedSize;



    @Override
    public void push(int x) {
        if(isFull()){
            iml= Arrays.copyOf(iml,2*iml.length);
        }
        iml[usedSize]=x;
        usedSize++;
    }

    public boolean isFull(){
        if(usedSize == iml.length){
            return true;
        }
        return false;
    }

    @Override
    public int pop() {

        if(empty()){
            throw new EmptyException(" 栈空");
        }
        usedSize--;
        return iml[usedSize];
    }

    @Override
    public int peek() {
        return iml[usedSize-1];
    }

    @Override
    public int size() {
        return usedSize;
    }

    @Override
    public boolean empty() {
        return usedSize ==0;
    }
}
